package com.xnf.article.controller.v1;

import com.xnf.api.article.ApArticleControllerApi;
import com.xnf.article.feigh.AdminFeign;
import com.xnf.article.service.ApArticleService;
import com.xnf.article.service.ApCollectionService;
import com.xnf.model.admin.dtos.ChannelDto;
import com.xnf.model.article.dtos.CollectionBehaviorDto;
import com.xnf.model.article.pojos.ApArticle;
import com.xnf.model.common.dtos.ResponseResult;
import com.xnf.model.mess.app.UpdateArticleMess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by xnf on 2022/3/4.
 */
@RestController
@RequestMapping("/api/v1")
public class ApArticleController implements ApArticleControllerApi {
    @Autowired
    private ApArticleService articleService;
    @Autowired
    private ApCollectionService apCollectionService;
    @Autowired
    private AdminFeign adminFeign;
    @PostMapping("/article/save")
    @Override
    public ApArticle saveArticle(@RequestBody ApArticle apArticle) {
        articleService.save(apArticle);
        return apArticle;
    }

    @PostMapping("/collection_behavior")
    @Override
    public ResponseResult collection(@RequestBody CollectionBehaviorDto dto) {
        return apCollectionService.collect(dto);
    }

    @Override
    @PostMapping("/article/loadChannel")
    public ResponseResult loadChannel(@RequestBody ChannelDto dto) {

        return ResponseResult.okResult(adminFeign.findChannels(dto));
    }

    @Override
    @PostMapping("/article/updateApArticleLVC")
    public ResponseResult updateApArticleLVC(@RequestBody UpdateArticleMess updateArticleMess) {
        return articleService.updateApArticleLVC(updateArticleMess.getType().name(),updateArticleMess.getArticleId());
    }

}
